package com.trt.contentcenter.controller.content;

import com.trt.contentcenter.auth.CheckAuthorization;
import com.trt.contentcenter.domain.dto.content.ShareAuditDTO;
import com.trt.contentcenter.domain.entity.content.Share;
import com.trt.contentcenter.service.content.ShareService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 授权
 * 1.土方法 (缺点,接口多，需要每个都写)
 *  @PutMapping("/audit/{id}")
 *     public Share auditById(@PathVariable Integer id, @RequestBody ShareAuditDTO auditDTO, HttpServletRequest request){
 *         Object role = request.getAttribute("role");
 *         // 判断
 *     }
 *
 * 2.Spring AOP
 */
@RestController
@RequestMapping("/admin/shares")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShareAdminController {

    private final ShareService shareService;

    @PutMapping("/audit/{id}")
    @CheckAuthorization("admin")
    public Share auditById(@PathVariable Integer id, @RequestBody ShareAuditDTO auditDTO){
        // TODO 认证、授权
        return this.shareService.auditById(id, auditDTO);
    }


}
